package com.niit.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Job;
import com.niit.service.JobService;
import com.niit.service.impl.JobServiceImpl;
import com.niit.utils.Page;
import com.niit.utils.WebKit;

@WebServlet("/ShowJobControllerByUser")
public class ShowJobControllerByUser extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String edu = request.getParameter("education");
		String exp = request.getParameter("expirence");
		String pagenum = request.getParameter("curPage");
		if("".equals(exp)){
			exp=null;
		}
		if("".equals(edu)){
			edu=null;
		}
		JobService js = new JobServiceImpl();
		Page<Job> page = null;
		if (edu==null & exp == null){	
			page = js.getPage(pagenum, WebKit.getServletURI(request));
		}else if(edu != null){
			page = js.getPage(pagenum, WebKit.getServletURI(request), 0, edu);
			String val = edu;
			request.setAttribute("education", val);
		}else if(exp != null){
			page = js.getPage(pagenum, WebKit.getServletURI(request), 1, exp);
			String val = exp;
			request.setAttribute("expirence", val);
		}
		request.setAttribute("page", page);		
		request.getRequestDispatcher("/jsp/user/hire.jsp").forward(request, response);
	}

}
